﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TreeData
{
    #region 单例
    private TreeData()
    {

    }
    private static TreeData _instance;
    public static TreeData Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = new TreeData();
            }
            return _instance;
        }
    }
    #endregion
    public List<TreePartData> AllTreeParts = new List<TreePartData>();

    public void SetSeed(GridData pos)
    {
        var seed = TreePartData.CreateTreePart(pos, null);
        AllTreeParts.Add(seed);
        pos.TreePart = seed;
    }

    public void GrowUp(GridData targetPos, TreePartData orgin)
    {
        var newPart = TreePartData.CreateTreePart(targetPos, orgin);
        AllTreeParts.Add(newPart);
    }

    public GrowUpRes CollectRes()
    {
        var result =  new GrowUpRes();
        for(int i = 0; i < AllTreeParts.Count; i++)
        {
            result += AllTreeParts[i].CollectRes();
        }
        return result;
    }

    public void Reset()
    {
        AllTreeParts = new List<TreePartData>();
    }
        
}
